<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 24266
  Date: 2023/12/9
  Time: 17:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="/css/bootstrap.min.css?v=3.3.7" rel="stylesheet">
    <link href="/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/css/animate.css" rel="stylesheet">
    <link href="/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg" >
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-6">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>学生管理</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="form_basic.html#">选项1</a>
                            </li>
                            <li><a href="form_basic.html#">选项2</a>
                            </li>
                        </ul>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm" action="/book/studentServlet?action=saveOrUpdate" method="post">
                        <input type="hidden" name="id" value="${entity.id}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" value="${entity.name}"
                                       type="text" aria-required="true" aria-invalid="true" class="error">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">学号：</label>
                            <div class="col-sm-8">
                                <input id="stuno" name="stuno" class="form-control" value="${entity.stuno}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">年龄：</label>
                            <div class="col-sm-8">
                                <input id="age" name="age" class="form-control" value="${entity.age}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">性别：</label>
                            <div class="col-sm-8">
                                <div class="radio-inline">
                                    <label>
                                        <input type="radio" ${entity.gender == '男'? 'checked':''} value="男" id="gender1" name="gender">男
                                    </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input type="radio" ${entity.gender == '女'? 'checked':''} value="女" id="gender2" name="gender">女
                                    </label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">邮箱：</label>
                            <div class="col-sm-8">
                                <input id="email" name="email" class="form-control" value="${entity.email}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">电话：</label>
                            <div class="col-sm-8">
                                <input id="talephone" name="talephone" class="form-control" value="${entity.talephone}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">微信：</label>
                            <div class="col-sm-8">
                                <input id="wechat" name="wechat" class="form-control" value="${entity.wechat}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">地址：</label>
                            <div class="col-sm-8">
                                <input id="address" name="address" class="form-control" value="${entity.address}"
                                       type="textarea" aria-required="true" aria-invalid="false" class="valid">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">分配院系：</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" id="departId" name="departId" onchange="dispatcherClasses(this.value)">
                                    <option value="-1" }>------请选择对应的院系------</option>
                                    <c:forEach items="${requestScope.departs}" var="depart">
                                        <option value="${depart.id}" ${depart.id ==
                                                entity.departId?'selected':''}>${depart.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">分配班级：</label>
                            <div class="col-sm-8">
                                <select class="form-control m-b" name="classid" id="classId">

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button  class="btn btn-default" onclick="resetPage()" type="button">取消</button>
                                <button class="btn btn-primary" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

</div>


</body>
<!-- 全局/js -->
<script src="/js/jquery.min.js?v=2.1.4"></script>
<script src="/js/bootstrap.min.js?v=3.3.7"></script>


<!-- Peity -->
<script src="/js/plugins/peity/jquery.peity.min.js"></script>

<!-- 自定义js -->
<script src="/js/content.js?v=1.0.0"></script>

<!-- Sweet alert -->
<script src="/js/plugins/sweetalert/sweetalert.min.js"></script>


<!-- iCheck -->
<script src="/js/plugins/iCheck/icheck.min.js"></script>

<!-- Peity -->
<script src="/js/demo/peity-demo.js"></script>>
<script >
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        dispatcherClasses($("#departId").val())

    });
    function resetPage(){
        window.location.href="/book/studentServlet?action=list"
    }
    function dispatcherClasses(deptId){
        if (deptId != -1){
            //需要通过ajax异步查询出院系对应的班级信息
            $.get("/book/classesServlet?action=findByDepartId&departId="+deptId,function (data){
                <%--<option value="${depart.id}" ${depart.id == entity.departId?'selected':''}>${depart.name}</option>--%>
                var opt = "";
                for(let i = 0;i < data.length;i++){
                    opt +="<option value="+data[i].id+">"+data[i].name+"</option>"
                }
                console.log(opt);
                $("#classId").html(opt);


            })

        }


    }
</script>
</html>
